package com.incar.chuxing.utils;

import android.animation.Animator;
import android.animation.ObjectAnimator;

import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;

public final class AnimatorUpdateOnSubscribe implements ObservableOnSubscribe<Boolean> {

    final ObjectAnimator animator;

    public AnimatorUpdateOnSubscribe(ObjectAnimator animator) {
        this.animator = animator;
    }


    @Override
    public void subscribe(ObservableEmitter<Boolean> emitter) throws Exception {



        Animator.AnimatorListener animatorListener = new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }

            @Override
            public void onAnimationEnd(Animator animation) {
                if (!emitter.isDisposed()) {
                    emitter.onNext(true);
                    Logger.i("logic","splsh消失");
                    emitter.onComplete();
                }
            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        };

        animator.addListener(animatorListener);

    }
}